<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Progma" content="no-cache" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/mm_training.css" type="text/css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/user.css" type="text/css" />
<link type="text/css" href="<%=request.getContextPath() %>/css/smoothness/jquery-ui-1.7.1.custom.css" rel="stylesheet"/>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/jquery/jquery-1.3.2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/scripts/jquery/jquery-ui-1.7.1.custom.js"></script>
<script type="text/javascript">

	/**
	 *
	 * 錢包狀態操作
	 *
	 * @param msgid 狀態變化文本ID
	 * @param action 提交操作ACTION名稱
	 * @param src 發生事件的源對象 
	 *
	 */
	function walletOperation(changenode, msgid, action, src) {
		// 下次操作按鈕NAME
		var nextMotion = "";
		// 下次操作按鈕文本
		var nextText = "";
		// 獲取當前操作NAME
		var motion = $(src).attr("name");
		// 獲取當前狀態
		var nextStatus = $(src).val();
		switch (motion) {
			case "open":
				nextMotion = "close";
				nextText = "关闭";
				break;
			case "melt":
				nextMotion = "freeze";
				nextText = "冻结";
				break;
			case "close":
				nextMotion = "open";
				nextText = "开启";
				break;
			case "freeze":
				nextMotion = "melt";
				nextText = "解冻";
				break;
			default:
				break;
		}
		var context = '<%=request.getContextPath()%>';
		// 請求開始時提示消息
		$("#loading").ajaxStart(function(){
			   $(this).dialog({
				   title:"正在操作,請稍等.......",
				   modal:true,
				   resizable:false,
				   draggable:false
			   });
		});
		// 請求完成
		 $("#loading").ajaxComplete(function(request, settings){
			 $(this).dialog("destroy");
		});
		var params = "";
		if ("expenseLimit" == changenode) {
			params = "expenseLimit=" + $("#expenseLimit").val();
		} else {
			params = changenode + "=" + motion;
		}
		// 提交請求
		$.ajax({
			   url: context + "/setup/" + action + ".do",
			   data: params,
			   dataType:"html",
			   success: function (data) {
				   // 清除所有錯誤消息 
				   $("span[id^='err_msg_']").each(function (index) {
					   // 清空錯誤消息
					   $(this).text("");
				   });
				   // 獲取錯誤消息
				   var errorMessage = $("li", data);
				   // 獲取返回消息 
				   var returnMessage = $("#returnMessage", data);

				   // 如果存在錯誤消息
				   if (errorMessage.length > 0) {
					   // 獲取消息
					   errorMessage.each(function (index) {
							// 獲取發生錯誤的字段ID
						   var id = $(this).attr("id");
						   // 獲取錯誤消息
						   var value = $(this).text();
						   // 顯示錯誤消息地方
						   var errorID = "err_msg_" + id;
						   // 設置錯誤消息
						   $("#" + errorID).text(value);
					   });
				   } else if (returnMessage.length > 0) {
					   if ("expenseLimit" != changenode) {
							// 設置NAME
							$(src).attr("name",nextMotion);
							// 設置value
							$(src).val(nextText);
							// 設置狀態
							$("#msg_" + msgid).text(nextStatus);
					   }
						$("<div></div>").html(returnMessage.text()).dialog({
							title:returnMessage.text(),
							resizable:false,
							draggable:false
						});
				   }
			   },
		   	   error: function (data) {
			   	   document.location.href = context + "/error.jsp?random=" + Math.random();
			   }
		});
	}
</script>
<style type="text/css">
.err_msg {
	color: red;
	font-size: 12px;
}

body {
	font-size: 12px;
}

.sidebarText {
	color: gray;
}

#content a {
	font-size: 12px;
	font-weight: normal;
	color: menutext;
}
#content td {
	font-size: 12px;
	font-weight: normal;
	color: menutext;
}
</style>
<title>錢包設置</title>
</head>
<body bgcolor="#64748B">
<jsp:include page="/head.jsp"></jsp:include>
<td width="230" valign="top" bgcolor="#26354a" colspan="2"><br />
<table width="230" cellspacing="0" cellpadding="0" border="0">
	<tbody>
			<s:if test="('company'.equals(userType) && 'parentManager'.equals(managerLevel)) || 'company'.equals(person)">
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath()%>/setup/account.do">修改我的個人資料</a><br/>
					<br/></td>
				</tr>
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath()%>/setup/changeMobileAction.do">關聯手機號碼變更</a><br/>
					<br/></td>
				</tr>
			</s:if>
			<s:if test="'company'.equals(userType) && 'parentManager'.equals(managerLevel)">
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath()%>/setup/goSubAccount.do">增加一個管理帳號</a><br />
					<br />
					</td>
				</tr>
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath() %>/setup/subAccountManage.do">子帳號管理</a><br />
					<br />
					</td>
				</tr>
			</s:if>
			<s:if test="('company'.equals(userType) && 'parentManager'.equals(managerLevel)) || 'person'.equals(userType)">
				<tr>
					<td width="230" id="padding" class="sidebarText"><a href="<%=request.getContextPath()%>/setup/wallet.do">錢包設置</a><br/>
					<br/></td>
				</tr>
			</s:if>
		</tbody>
</table>
</td>
<td valign="top" width='100%'>
<div style="border: 1px solid #DADADA; min-width: 700px;">
<table id="content" width="100%" cellspacing="0" cellpadding="0" border="0">
	<tbody>
		<tr>
			<td width="50%" align="center" height="50"><a href="#">余款變更手機通知是否開啟</a> <br />
			</td>
			<td>你的余款變更手機通知当前状态为: <s:if test="mobileNotify == 'open'"><span id="msg_mobile">开启</span>,<input type="button" value="关闭" name="close" onclick="walletOperation('mobileNotify','mobile','mobileNotifySetup',this);"/>?</s:if> <s:elseif test="mobileNotify == 'close'"><span id="msg_mobile">关闭</span>,<input type="button" value="开启" name="open" onclick="walletOperation('mobileNotify','mobile','mobileNotifySetup',this);"/>?</s:elseif> <br />
			<span id="err_msg_mobileNotify" class="err_msg"></span>
			</td>
		</tr>
		<tr>
			<td align="center" height="50"><a href="#">余款變更郵件通知是否開啟</a> <br />
			</td>
			<td>你的余款變更郵件通知当前状态为: <s:if test="emailNotify == 'open'"><span id="msg_email">开启</span>,<input type="button" value="关闭" name="close" onclick="walletOperation('emailNotify','email','emailNotifySetup',this);"/>?</s:if> <s:elseif test="emailNotify == 'close'"><span id="msg_email">关闭</span>,<input type="button" value="开启" name="open" onclick="walletOperation('emailNotify','email','emailNotifySetup',this);"/>?</s:elseif> <br />
			<span id="err_msg_emailNotify" class="err_msg"></span>
			</td>
		</tr>
		<tr>
			<td align="center" height="50"><a href="#">單次消費限制</a> <br />
			</td>
			<td>
			<select name="expenseType" id="expenseType">
				<option value="time">單次消費不得大于</option>
				<option value="day">每日消費不得大于</option>
			</select>			
			<input type="text" name="expenseLimit" id="expenseLimit" />元臺幣
			<input type="button" name="limit" id="limit" value="限制" onclick="walletOperation('expenseLimit','','consumeLimitSetup',this);"/>
			<span id="err_msg_expenseLimit" class="err_msg"></span>
			<br />
			</td>
		</tr>
		<tr>
			<td align="center" height="50"><a href="#">凍結錢包</a> <br />
			</td>
			<td>你的錢包当前状态为: 
			<s:if test="freezeWallet == 'melt'"><span id="msg_wallet">未凍結</span>,<input type="button" value="凍結" name="freeze" onclick="walletOperation('freezeWallet','wallet','walletSetup',this);"/>?</s:if> 
			<s:elseif test="freezeWallet == 'freeze'"><span id="msg_wallet">已凍結</span>,<input type="button" value="解凍" name="melt" onclick="walletOperation('freezeWallet','wallet','walletSetup',this);"/>?</s:elseif> <br />
			<span id="err_msg_freezeWallet" class="err_msg"></span>
			</td>
		</tr>
	</tbody>
</table>
</div>
</td>
<div id="loading" style="display: none;">正在操作,請稍等.......</div>
<jsp:include page="/footer.jsp"></jsp:include>
</body>
</html>